import time

from django.db import models

# Create your models here.


class User(models.Model):

	id = models.AutoField(primary_key=True)
	nick_name = models.CharField(max_length=64, default="", verbose_name='昵称')  # 昵称
	email = models.CharField(max_length=128, default="", verbose_name='登录凭证')  # 登录凭证
	password = models.CharField(max_length=128, verbose_name='登录秘钥')  # 登录秘钥
	register_time = models.IntegerField(default=time.time(), verbose_name='注册时间')  # 注册时间
	last_login_time = models.IntegerField(default=time.time(), verbose_name='上次登录时间')  # 上次登录时间
	level = models.IntegerField(default=1, verbose_name='用户等级')  # 用户等级
	is_delete = models.IntegerField(default=0, verbose_name='是否注销')  # 是否注销
	is_valid = models.IntegerField(default=1, verbose_name='是否禁用')  # 是否被禁用 1 不被禁用
	avatar = models.TextField(default='/static/image/default.jpg', verbose_name='用户头像')  # 用户头像
	tags = models.CharField(default="普通用户", verbose_name="用户的标签", max_length=128) # 用户标签
	info = models.CharField(max_length=1024, default='这个用户很懒 啥也没有留下', verbose_name='用户介绍')  # 用户介绍

	class Meta:
		db_table = "user_db"
		unique_together = (("email",),)
		verbose_name = '用户'
		verbose_name_plural = verbose_name

	def __str__(self):
		return self.nick_name

	def delete(self):
		self.is_delete = 1
		super().save()


class LevelGroup(models.Model):
	# 角色列表
	id = models.AutoField(primary_key=True)
	level = models.IntegerField(default=1, verbose_name="权限等级")
	score = models.IntegerField(default=0, verbose_name="所需分数")
	tag = models.CharField(max_length=128, default="普通", verbose_name="等级称号")

	class Meta:
		db_table = "level_group_db"


class Role(models.Model):
	# 用户角色
	id = models.AutoField(primary_key=True)
	uid = models.ForeignKey(User, on_delete="SET_DEFAULT", default='', db_column='uid', verbose_name='用户')  # 粉丝id
	level_group = models.ForeignKey(LevelGroup, on_delete="SET_DEFAULT", default='', db_column='level_group', verbose_name='角色')  # 粉丝id

	class Meta:
		db_table = "role_db"
		unique_together = (("uid", "level_group"),)


class Fans(models.Model):

	id = models.AutoField(primary_key=True)
	fid = models.IntegerField()  # 粉丝id
	oid = models.IntegerField()  # 被关注的博主id

	class Meta:
		db_table = "fan_db"
		unique_together = (("fid", "oid"),)
